package com.pxl.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pxl.springbootinit.common.BaseResponse;
import com.pxl.springbootinit.common.ErrorCode;
import com.pxl.springbootinit.common.ResultUtils;
import com.pxl.springbootinit.model.dto.task.TaskReviewForm;
import com.pxl.springbootinit.model.vo.TaskReviewVO;
import com.pxl.springbootinit.service.TaskReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 任务评论接口层
 *
 * @author MADAO
 * @create 2024 - 12 - 20 15:41
 */
@Slf4j
@RestController
@RequestMapping("/task/review")
public class TaskReviewController {

    @Resource
    private TaskReviewService taskReviewService;

    /**
     * 新增任务评论
     * @param taskReviewForm
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> addReview(@RequestBody TaskReviewForm taskReviewForm) {
        return ResultUtils.success(taskReviewService.addReview(taskReviewForm));
    }

    /**
     * 删除任务评论
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteReview(@PathVariable Long id) {
        if (id == null){
            return ResultUtils.error(ErrorCode.PARAMS_ERROR,"参数不能为空");
        }
        return ResultUtils.success(taskReviewService.removeById(id));
    }

    /**
     * 分页获取任务的评论
     * @param taskReviewForm
     * @return
     */
    @GetMapping("/admin/page")
    public BaseResponse<Page<TaskReviewVO>> pageReview(TaskReviewForm taskReviewForm) {
        return ResultUtils.success(taskReviewService.pageReview(taskReviewForm));
    }


    /**
     * 获取到别人对我的评价
     */
    @GetMapping("/my")
    public BaseResponse<List<TaskReviewVO>> myReview(HttpServletRequest request) {
        return ResultUtils.success(taskReviewService.myReview(request));
    }
}
